{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "c02be68b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "96c4dc8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1 = np.array([[1,2],[2,3],[3,4]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "eda268fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [2 3]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "print(nd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "988043c6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(type(nd1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9a80442b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "aca61046",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c94bd14f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "ad2b1cef",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = np.array([[\"1\",\"2\"],[\"3\",\"4\"]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "594eebc5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['1' '2']\n",
      " ['3' '4']]\n"
     ]
    }
   ],
   "source": [
    "print(nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "5ab672a3",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "cannot perform reduce with flexible type",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_15996/1778844841.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnd2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\users\\zzk10\\python3.7.9\\lib\\site-packages\\numpy\\core\\_methods.py\u001b[0m in \u001b[0;36m_amax\u001b[1;34m(a, axis, out, keepdims, initial, where)\u001b[0m\n\u001b[0;32m     38\u001b[0m def _amax(a, axis=None, out=None, keepdims=False,\n\u001b[0;32m     39\u001b[0m           initial=_NoValue, where=True):\n\u001b[1;32m---> 40\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0mumr_maximum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mout\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkeepdims\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minitial\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mwhere\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     41\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     42\u001b[0m def _amin(a, axis=None, out=None, keepdims=False,\n",
      "\u001b[1;31mTypeError\u001b[0m: cannot perform reduce with flexible type"
     ]
    }
   ],
   "source": [
    "nd2.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f67717ed",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "nd2 = nd2.astype(\"int\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1793bddd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "fa1e5463",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd3 = np.array([[1,2,3],[4,5,6],[7,8,9],[1,2,3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "ca20f65b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6],\n",
       "       [7, 8, 9],\n",
       "       [1, 2, 3]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "e20f786e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 3)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "fbb333c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 索引\n",
    "nd3[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "bdf6f658",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([7, 8, 9])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "9b359a3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 5, 6],\n",
       "       [7, 8, 9]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[1:3:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "d0ab4c1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5, 6],\n",
       "       [8, 9]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 切片\n",
    "# [行的切片,列的切片]\n",
    "# [行的起始位置:行的结束位置:步长,列的起始位置:列的结束位置:步长]\n",
    "nd3[1:3:1,1:3:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "afa5d7c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd4 = np.array(\n",
    "[\n",
    "    [0,1,2,3,4,5],\n",
    "    [10,11,12,13,14,15],\n",
    "    [20,21,22,23,24,25],\n",
    "    [30,31,32,33,34,35],\n",
    "    [40,41,42,43,44,45],\n",
    "    [50,51,52,53,54,55],\n",
    "]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "980d7cd2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [10, 11, 12, 13, 14, 15],\n",
       "       [20, 21, 22, 23, 24, 25],\n",
       "       [30, 31, 32, 33, 34, 35],\n",
       "       [40, 41, 42, 43, 44, 45],\n",
       "       [50, 51, 52, 53, 54, 55]])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "864e23b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1, 12, 23, 34, 45])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 坐标\n",
    "nd4[(0,1,2,3,4),(1,2,3,4,5)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "98aa070a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2, 22, 52])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4[[0,2,5],2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "af9c43f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd5 = np.array([1,0,1,0,0,1],dtype='bool')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "79134e24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True, False,  True, False, False,  True])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "ef2ff4e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2, 22, 52])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 布尔索引\n",
    "nd4[nd5,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "8bbc0553",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True],\n",
       "       [False,  True, False,  True, False,  True]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4%2 == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "bfe46d6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1,  3,  5, 11, 13, 15, 21, 23, 25, 31, 33, 35, 41, 43, 45, 51, 53,\n",
       "       55])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4[nd4%2 == 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "0528df9e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    }
   ],
   "source": [
    "nd1 = np.array([[1,2,3],[4,5,6]])\n",
    "print(nd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "2ecdd280",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 3 4]\n",
      " [1 2 3]]\n"
     ]
    }
   ],
   "source": [
    "nd2 = np.array([[2,3,4],[1,2,3]])\n",
    "print(nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "addb368d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 5 7]\n",
      " [5 7 9]]\n",
      "[[-1 -1 -1]\n",
      " [ 3  3  3]]\n",
      "[[ 2  6 12]\n",
      " [ 4 10 18]]\n",
      "[[0.5        0.66666667 0.75      ]\n",
      " [4.         2.5        2.        ]]\n"
     ]
    }
   ],
   "source": [
    "# 对位运算\n",
    "print(nd1+nd2)\n",
    "print(nd1-nd2)\n",
    "print(nd1*nd2)\n",
    "print(nd1/nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "7aa10dfe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [2 3]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "# 矩阵运算\n",
    "nd3 = np.array([[1,2],[2,3],[3,4]])\n",
    "print(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "346de8a2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[14, 20],\n",
       "       [32, 47]])"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(nd1,nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "504c4a52",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.        , 1.91666667],\n",
       "       [8.5       , 5.16666667]])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(nd1,1/nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "0bad21f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\zzk10\\python3.7.9\\lib\\site-packages\\ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in arccos\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0., nan],\n",
       "       [nan, nan],\n",
       "       [nan, nan]])"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.arccos(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f90ee17",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
